//
//  LGLungFollowAuditController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/8/8.
//  随访审批

#import "LGLungFollowAuditController.h"
//患者详情
#import "LGPatientDetailController_YHJK.h"
#import "LGPatientDetailController2.h"
#import "LGLungFollowAuditCell.h"
@interface LGLungFollowAuditController ()<UITableViewDelegate,UITableViewDataSource>
/**   */
@property (nonatomic , strong)UITextField *searchTF;
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;
/**   */
@property (nonatomic , copy)NSString *keyword;

@end

@implementation LGLungFollowAuditController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.keyword = @"";
    self.title = @"随访审批";
    [self.view addSubview:self.searchTF];
    [self.view addSubview:self.tableView];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/Careplan/careplanCheckedLists" parameters:@{@"keyword":self.keyword} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            self.dataArray = returnData;
            [self.tableView reloadData];
        }
    } error:^(NSError *error) {
        
    }];
}

-(void)textFieldEditingChanged:(UITextField *)textField{
    self.keyword = textField.text.length>0?textField.text:@"";
    [self requestData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGLungFollowAuditCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.searchTF resignFirstResponder];
    NSDictionary *tempDic = self.dataArray[indexPath.row];
    NSString *nodePage = LGNSString(tempDic[@"nodepage"]);
    if ([nodePage isEqualToString:@"1"]) {
        //市一慢阻肺
        LGPatientDetailController2 *controller = [[LGPatientDetailController2 alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.levelid = LGNSString(tempDic[@"level_id"]);
        controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }else{
        //其他
        LGPatientDetailController_YHJK *controller = [[LGPatientDetailController_YHJK alloc]init];
        controller.patientid = LGNSString(tempDic[@"patient_id"]);
        controller.levelid = LGNSString(tempDic[@"level_id"]);
        controller.diseaseCode = LGNSString(tempDic[@"disease_code"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}

-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, viewPix(45), Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGLungFollowAuditCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(10))];
    }
    return _tableView;
}

-(UITextField *)searchTF{
    if(!_searchTF){
        _searchTF = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(6), Screen_W-viewPix(32), viewPix(32))];
        [_searchTF setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _searchTF.backgroundColor = [UIColor whiteColor];
        _searchTF.tintColor = [UIColor colorWithString:@"#333333"];
        _searchTF.textColor = [UIColor colorWithString:@"#333333"];
        _searchTF.textAlignment = NSTextAlignmentLeft;
        _searchTF.keyboardType = UIKeyboardTypeDefault;
        _searchTF.placeholder = @"输入患者姓名/病案号进行查找";
        _searchTF.cornerRidus = viewPix(16);
        _searchTF.font = LGFont(15);
        _searchTF.leftViewMode = UITextFieldViewModeAlways;
        _searchTF.leftView = [self leftView];
        [_searchTF addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    }
    return _searchTF;
}

-(UIView *)leftView{
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewPix(36), 32)];
    UIImageView *searchIcon = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), 8, 16, 16)];
    searchIcon.image = [UIImage imageNamed:@"searchGray16"];
    [leftView addSubview:searchIcon];
    return leftView;
}

@end

